//顺序栈	
#include<stdio.h>
#include<malloc.h>

#define MAXSIZE 100
typedef int SElemType;

typedef struct{
	SElemType *base;//栈底指针
	SElemType *top;//栈顶指针
	int stacksize;//栈可用最大容量
}SqStack;


//栈的初始化
void InitStack(SqStack *&s);

//判断栈是否为空
bool StackEmpty(SqStack s);

//求长度
int StackLength(SqStack *&s);


//清空一个栈
void StackStack(SqStack *&s);

//销毁栈
void StackDestroy(SqStack *&s);

//入栈
void StackPush(SqStack *&s,SElemType e);

//出栈
void StackPop(SqStack *&s,SElemType &e);

int main()
{
	SqStack* s;
	InitStack(s);
	
	
	
	
	return 0;
}

//初始化栈
void InitStack(SqStack *&s)
{
	s->base = (SElemType*)malloc(sizeof(SElemType)*MAXSIZE);
	if(!s->base)exit(-2);
	s->top = s->base;
	s->stacksize = MAXSIZE;
	
}


//判断栈是否为空
bool StackEmpty(SqStack s)
{
	if(s.top==s.base)
	{
		return true;	
	}
	else return false;
}


//求长度
int StackLength(SqStack *&s)
{
	return s->top-s->base;
}


//清空一个栈
void StackStack(SqStack *&s)
{
	if(s->base) s->top = s->base;//如果存在
}



//销毁栈
void StackDestroy(SqStack *&s)
{
	if(s->base)
	{
		free(s->base);
		s->stacksize=0;
		s->base = s->top = NULL;
	}
}


//入栈
void StackPush(SqStack *&s,SElemType e)
{
	if(s->top-s->base==MAXSIZE)
	{
		return;
	}
	*s->top++ = e;
	
	
}


//出栈
void StackPop(SqStack *&s,SElemType &e)
{
	if(s->top==s->base)
	{
		return;
	}
	e = *--s->top;//先指针下移，然后取出其位置的值
}
